const Router = require('koa-router');
const db = require('../libs/db');
const response = require('../libs/result');
let router = new Router();


/**
 * @api {post} /api/v1/consultation/querylist  资讯列表
 * @apiDescription 资讯列表
 * @apiName querylist
 * @apiParamExample {json} Request-Example:
 *     {
 *       "page": 1,
 *       "pageSize": 10
 *     }
 * @apiParam (参数) {String} page   页数，从1开始
 * @apiParam (参数) {String} pageSize   每页条数
 * @apiSampleRequest /api/v1/consultation/querylist
 * @apiGroup consultation
 * @apiVersion 1.0.0
 */
router.post('/querylist', async ctx => {
    let { page, pageSize } = ctx.request.body;
    let selectStr = ' * ';
    let data = await db.queryPage(ctx, 'content_news', selectStr, null, page || 1, pageSize || 6);

    response(ctx, 200, data, '资讯列表');
})

/**
 * @api {post} /api/v1/consultation/queryById  资讯详情
 * @apiDescription 资讯详情
 * @apiName queryById
 * @apiParam (参数) {String} id 资讯编号id
 * @apiSampleRequest /api/v1/consultation/queryById
 * @apiGroup consultation
 * @apiVersion 1.0.0
 */
router.post('/queryById', async ctx => {
    let { id } = ctx.request.body;
    let data = await db.queryById(ctx, 'content_news', id);

    response(ctx, 200, data, '资讯详情');
})

module.exports = router.routes()